home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-11-19 | 2.4 KB | 73 lines | [TEXT/MPS ] |
- /*
- File: TArbitratorExample1.cp
-
- Contains: This module show an example use of the TArbitrator class.
-
- Copyright: © 1993 by Apple Computer, Inc., all rights reserved.
-
- */
-
- #include "TInitSLM.h" // the TInitSLM class and SLM include files
-
- ///————————————————————————————————————————————————————————————————————————————————————
- /// CONSTANTS
- ///————————————————————————————————————————————————————————————————————————————————————
-
- // id of the object we register with the arbitrator
- #define kLinkObjectID "slm:exam$link1"
-
- /*————————————————————————————————————————————————————————————————————————————————————
- main
-
- This is a simple demonstration of how to use the TArbitrator class. It creates a
- new arbitrator and registers an object with it. Once the object is registered
- other clients having access to the same TArbitrator can lookup the object if they
- know the ID of that the object was registered with. Once the ID and the arbitrator
- is known the client can lookup the object by calling "LookupObject".
- ————————————————————————————————————————————————————————————————————————————————————*/
-
- main()
- {
- TInitSLM initLibraryManager; // initialize the shared library manager
-
- if( initLibraryManager.Failed() ) // If we failed, let's go home
- return 1;
-
- TArbitrator *arbitrator;
-
- if( arbitrator = new TArbitrator ) { // create our own arbitrator
-
- cout << "Got a new arbitrator" << endl;
-
- TLink *link;
-
- if( link = new TLink ) { // This is the object we are arbitrating
-
- cout <<"Allocating and registering an object…" << endl;
-
- // Register the object so other clients can look it up
- OSErr err = arbitrator->RegisterObject( kLinkObjectID, (void *)link );
- if( err != kNoError)
- cout << "ERROR ==> {RegisterObject} = " << err << endl;
- else {
- // see if we can find the object by ID
- TLink *object = (TLink *)arbitrator->LookupObject( kLinkObjectID );
-
- if( object != link ) // if object returned != our object
- cout << "Something fishy, we got the wrong object" << endl;
- else
- cout << "LookupObject returned our Registered object" << endl;
-
- // since we are the only one using this object we can go ahead
- // unregister and then delete the object
- if( object = (TLink *)arbitrator->UnregisterObject( kLinkObjectID ) )
- cout << "Unregistered the object OK" << endl;
- }
- delete link; // we are done w/ the object
- }
- delete arbitrator; // and done with arbitrator
- }
-
- return 0;
- }
-